import GC from "@grapecity-software/spread-sheets";

const openOptions = {
    openMode: 0,
    includeStyles: true,
    includeFormulas: true,
    frozenColumnsAsRowHeaders: false,
    frozenRowsAsColumnHeaders: false,
    fullRecalc: true, // 是否重新计算,是的话只会显示loading
    dynamicReferences: true,
    calcOnDemand: false,
    includeUnusedStyles: true,
    incrementalLoading: false,
    encoding: "UTF-8",
    rowDelimiter: "\r\n",
    columnDelimiter: ","
};
const saveOptions = {
    includeBindingSource: false,
    includeStyles: true,
    includeFormulas: true,
    saveAsView: false,
    rowHeadersAsFrozenColumns: false,
    columnHeadersAsFrozenRows: false,
    includeAutoMergedCells: false,
    includeCalcModelCache: false,
    saveR1C1Formula: false,
    includeUnusedNames: true,
    includeEmptyRegionCells: true,
    encoding: "UTF-8",
    rowDelimiter: "\r\n",
    columnDelimiter: ",",
    sheetIndex: 0,
    row: 0,
    column: 0,
    rowCount: 200,
    columnCount: 20,
};
const openOptionsConfig = {
    sjs: [
        {
            propName: "openMode",
            type: "select",
            displayText: "OpenMode",
            options: [{
                name: 'normal',
                value: 0
            }, {
                name: 'lazy',
                value: 1
            }, {
                name: 'incremental',
                value: 2
            }],
            default: 0
        },
        {
            propName: "includeStyles",
            type: "boolean",
            default: true
        },
        {
            propName: "includeFormulas",
            type: "boolean",
            default: true
        },
        {
            propName: "fullRecalc",
            type: "boolean",
            default: false
        },
        {
            propName: "dynamicReferences",
            type: "boolean",
            default: true
        },
        {
            propName: "calcOnDemand",
            type: "boolean",
            default: false
        },
        {
            propName: "includeUnusedStyles",
            type: "boolean",
            default: true
        }
    ],
    xlsx: [
        {
            propName: "openMode",
            type: "select",
            displayText: "OpenMode",
            options: [{
                name: 'normal',
                value: 0
            }, {
                name: 'lazy',
                value: 1
            }, {
                name: 'incremental',
                value: 2
            }],
            default: 0
        },
        {
            propName: "includeStyles",
            type: "boolean",
            default: true
        },
        {
            propName: "includeFormulas",
            type: "boolean",
            default: true
        },
        {
            propName: "frozenColumnsAsRowHeaders",
            type: "boolean",
            default: false
        },
        {
            propName: "frozenRowsAsColumnHeaders",
            type: "boolean",
            default: false
        },
        {
            propName: "fullRecalc",
            type: "boolean",
            default: true
        },
        {
            propName: "dynamicReferences",
            type: "boolean",
            default: true
        },
        {
            propName: "calcOnDemand",
            type: "boolean",
            default: true
        },
        {
            propName: "includeUnusedStyles",
            type: "boolean",
            default: true
        },
    ],
    ssjson: [
        {
            propName: "includeStyles",
            type: "boolean",
            default: true
        },
        {
            propName: "includeFormulas",
            type: "boolean",
            default: true
        },
        {
            propName: "frozenColumnsAsRowHeaders",
            type: "boolean",
            default: false
        },
        {
            propName: "frozenRowsAsColumnHeaders",
            type: "boolean",
            default: false
        },
        {
            propName: "fullRecalc",
            type: "boolean",
            default: false
        },
        {
            propName: "incrementalLoading",
            type: "boolean",
            default: false
        }
    ],
    csv: [
        {
            propName: "encoding",
            type: "string",
            default: "UTF-8"
        },
        {
            propName: "rowDelimiter",
            type: "string",
            default: "\r\n"
        },
        {
            propName: "columnDelimiter",
            type: "string",
            default: ","
        }
    ]
};

const saveOptionsConfig = {
    sjs: [{
        propName: "includeBindingSource",
        type: "boolean",
        default: false
    },
        {
            propName: "includeStyles",
            type: "boolean",
            default: true
        },
        {
            propName: "includeFormulas",
            type: "boolean",
            default: true
        },
        {
            propName: "saveAsView",
            type: "boolean",
            default: false
        },
        {
            propName: "includeAutoMergedCells",
            type: "boolean",
            default: false
        },
        {
            propName: "includeCalcModelCache",
            type: "boolean",
            default: false
        },
        {
            propName: "saveR1C1Formula",
            type: "boolean",
            default: false
        },
        {
            propName: "includeUnusedNames",
            type: "boolean",
            default: true
        },
        {
            propName: "includeEmptyRegionCells",
            type: "boolean",
            default: true
        },
    ],
    xlsx: [{
        propName: "includeBindingSource",
        type: "boolean",
        default: false
    },
        {
            propName: "includeStyles",
            type: "boolean",
            default: true
        },
        {
            propName: "includeFormulas",
            type: "boolean",
            default: true
        },
        {
            propName: "saveAsView",
            type: "boolean",
            default: false
        },
        {
            propName: "rowHeadersAsFrozenColumns",
            type: "boolean",
            default: false
        },
        {
            propName: "columnHeadersAsFrozenRows",
            type: "boolean",
            default: false
        },
        {
            propName: "includeAutoMergedCells",
            type: "boolean",
            default: false
        },
        {
            propName: "includeUnusedNames",
            type: "boolean",
            default: true
        },
        {
            propName: "includeEmptyRegionCells",
            type: "boolean",
            default: true
        },
    ],
    ssjson: [{
        propName: "includeBindingSource",
        type: "boolean",
        default: false
    },
        {
            propName: "includeStyles",
            type: "boolean",
            default: true
        },
        {
            propName: "includeFormulas",
            type: "boolean",
            default: true
        },
        {
            propName: "saveAsView",
            type: "boolean",
            default: false
        },
        {
            propName: "rowHeadersAsFrozenColumns",
            type: "boolean",
            default: false
        },
        {
            propName: "columnHeadersAsFrozenRows",
            type: "boolean",
            default: false
        },
        {
            propName: "includeAutoMergedCells",
            type: "boolean",
            default: false
        },
    ],
    csv: [{
        propName: "encoding",
        type: "string",
        default: "UTF-8"
    },
        {
            propName: "rowDelimiter",
            type: "string",
            default: "\r\n"
        },
        {
            propName: "columnDelimiter",
            type: "string",
            default: ","
        },
        {
            propName: "sheetIndex",
            type: "number",
            default: 0
        },
        {
            propName: "row",
            type: "number",
            default: 0
        },
        {
            propName: "column",
            type: "number",
            default: 0
        },
        {
            propName: "rowCount",
            type: "number",
            default: 200
        },
        {
            propName: "columnCount",
            type: "number",
            default: 20
        },
    ]
};
const getFileType = function (file: File) {
    if (!file) {
        return '';
    }

    let fileName = file.name;
    let extensionName = fileName.substring(fileName.lastIndexOf(".") + 1);

    if (extensionName === 'sjs') {
        return 'sjs';
    } else if (extensionName === 'xlsx' || extensionName === 'xlsm') {
        return 'xlsx';
    } else if (extensionName === 'ssjson' || extensionName === 'json') {
        return 'ssjson';
    } else if (extensionName === 'csv') {
        return 'csv';
    }
}
const mapExportFileType = function (fileType: string) {
    if (fileType === 'ssjson') {
        return GC.Spread.Sheets.FileType.ssjson;
    } else if (fileType === 'csv') {
        return GC.Spread.Sheets.FileType.csv;
    }
    return GC.Spread.Sheets.FileType.excel;
}

export {
    openOptions,
    saveOptions,
    openOptionsConfig,
    saveOptionsConfig,
    getFileType,
    mapExportFileType
}
type FileType = 'sjs' | 'xlsx' | 'ssjson' | 'csv';
export type {
    FileType
}